package com.peng.old.util;

import java.util.Arrays;
import java.util.Random;

/**
 * 算法工具类
 */
public class SortUtil {
    private static int[] randomArr ;


    public static int[] makeRandomArray(int length){
        randomArr = new int[length];
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            randomArr[i] = random.nextInt();
        }
        int[] copyArr = new int[length];
        System.arraycopy(randomArr,0,copyArr,0,randomArr.length);

        return copyArr;
    }


    public static boolean checkResult(int[] sortedArr){
        int[] copyArr = new int[randomArr.length];
        System.arraycopy(randomArr,0,copyArr,0,randomArr.length);
        Arrays.sort(copyArr);
//        System.out.println("trueArr:"+Arrays.toString(copyArr));
//        System.out.println("sortedArr:"+Arrays.toString(sortedArr));
        for (int i = 0; i < copyArr.length; i++) {
            if(copyArr[i]!=sortedArr[i]){
                return false;
            }

        }
        return true;

    }


    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void swap(Integer[] arr, Integer i, Integer j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
